package com.lcf.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.lcf.framework.vo.PageVO;
import com.lcf.system.dao.MovieNewsDao;
import com.lcf.system.dto.MovieNewsDTO;
import com.lcf.system.entity.MovieNews;
import com.lcf.system.query.MovieNewsPageQuery;
import com.lcf.system.service.MovieNewsService;
import com.lcf.system.vo.MovieNewsVO;
import org.springframework.stereotype.Service;

/**
 * 电影资讯(MovieNews)表服务实现类
 *
 * @author lcf
 * @since 2025-05-07 22:23:22
 */
@Service("movieNewsService")
public class MovieNewsServiceImpl extends ServiceImpl<MovieNewsDao, MovieNews> implements MovieNewsService {

    @Override
    public void add(MovieNewsDTO dto) {
        BeanUtil.copyProperties(dto, MovieNews.class).insert();
    }

    @Override
    public void edit(long id, MovieNewsDTO dto) {
        MovieNews movieNews = BeanUtil.copyProperties(dto, MovieNews.class);
        movieNews.setId(id);
        movieNews.updateById();
    }

    @Override
    public void delete(long id) {
        removeById(id);
    }

    @Override
    public PageVO<MovieNewsVO> page(MovieNewsPageQuery query) {
        Page<MovieNews> page = Db.lambdaQuery(MovieNews.class)
                .orderByDesc(MovieNews::getCreateTime)
                .page(query.toPage());
        return new PageVO<>(page, MovieNewsVO.class);
    }

    @Override
    public MovieNewsVO get(long id) {
        return BeanUtil.copyProperties(getById(id), MovieNewsVO.class);
    }
}

